package com.zhang.hadoop.netty.nio.buffer;

import java.nio.ByteBuffer;

/**
 * @author: zhang yufei
 * @create: 2022-01-09 17:40
 * @description: 放入和取数数据类型和顺序必须一致
 **/
public class NIOByteBufferPutGet {

    public static void main(String argsp[]) {
        ByteBuffer buffer = ByteBuffer.allocate(64);

        //类型化方式放入数据
        buffer.putInt(100);
        buffer.putLong(9L);
        buffer.putChar('张');
        buffer.putShort((short) 4);

        buffer.flip();

        System.out.println(buffer.getInt());
        System.out.println(buffer.getLong());
        System.out.println(buffer.getChar());
        System.out.println(buffer.getShort());
    }
}
